﻿@model Fengsoft.AIBlog.Web.Models.QuestionnairePartial
@if (Model.Questionnaire==null)
{
    <span>Questionnaire not found.</span>
}
else
{
    <!--=== Breadcrumbs ===-->
    <div class="breadcrumbs margin-bottom-40">
        <div class="container">
            <h1 class="pull-left">@Model.Questionnaire.Description</h1>
        </div>
    </div>
    <!--/breadcrumbs-->
    <!--=== End Breadcrumbs ===-->
    <!--=== Content Part ===-->
    <div class="container">
        <div class="row">
            <!--Begin Content-->
            <div class="col-md-12">
                @if (Model.Questionnaire.Published)
                {
                    if (Model.Questionnaire.EffectiveDate<=DateTime.Now&&Model.Questionnaire.ExpiredDate.GetValueOrDefault(DateTime.MaxValue)>=DateTime.Now)
                    {
                        using (Html.BeginForm())
                        {
                            @Html.AntiForgeryToken()
                            @Html.Hidden("ReferenceName",Model.Questionnaire.ReferenceName)
                            foreach (var question in Model.Questionnaire.Questions.OrderBy(x => x.QuestionNumber))
                            {
                                <div class="form-group">
                                    @switch (question.InputType)
                                    {
                                        case "CheckBox":
                                            <label>@(question.QuestionNumber). @Html.Raw(question.Title)</label>
                                            foreach (var option in question.Options.OrderBy(x=>x.OptionNumber))
                                            {
                                                <div class="checkbox">
                                                    <label>
                                                        <input id="chk@(question.InputName)@option.QuestionnaireOptionID" name="@question.InputName" type="checkbox" value="@option.Value" />
                                                        @option.Label
                                                    </label>
                                                </div>
                                            }
                                            break;
                                        case "DropDownList":
                                            <label for="drop@(question.InputName)">@(question.QuestionNumber). @Html.Raw(question.Title)</label>
                                            <select id="drop@(question.InputName)" name="@question.InputName" class="form-control">
                                                @foreach (var option in question.Options.OrderBy(x=>x.OptionNumber))
                                                {
                                                    <option value="@option.Value">@option.Label</option>
                                                }
                                            </select>
                                            break;
                                        case "RadioButton":
                                            <label>@(question.QuestionNumber). @Html.Raw(question.Title)</label>
                                            foreach (var option in question.Options.OrderBy(x=>x.OptionNumber))
                                            {
                                                <div class="radio">
                                                    <label>
                                                        <input id="rad@(question.InputName)@option.QuestionnaireOptionID" name="@question.InputName" type="radio" value="@option.Value" />
                                                        @option.Label
                                                    </label>
                                                </div>
                                            }
                                            break;
                                        case "TextBox":
                                            <label for="txt@(question.InputName)">@(question.QuestionNumber). @Html.Raw(question.Title)</label>
                                            <input id="txt@(question.InputName)" name="@question.InputName" type="text" class="form-control" placeholder="@question.Options.First().Label" value="@question.Options.First().Value" />
                                                break;
                                    }
                                </div>
                            }
                            <button id="btn@(Model.Questionnaire.ReferenceName)" type="submit" class="btn-u btn-u-blue">Submit</button>
                        }
                    }
                    else
                    {
                        <div class="alert alert-info">@QuestionnaireResource.QuestionnaireExpired</div>
                    }
                }
                else
                {
                    <div class="alert alert-info">@QuestionnaireResource.QuestionnaireNotPublish</div>
                }
            </div><!--End Content-->
        </div>
    </div><!--/container-->     
    <!--=== End Content Part ===-->
}